import 'package:flutter/material.dart';
import 'package:video_player/video_player.dart';

class ZsnSpeed extends StatelessWidget {
  final VideoPlayerController videoController;
  const ZsnSpeed({super.key, required this.videoController});

  @override
  Widget build(BuildContext context) {
    return TextButton(
        onPressed: () {
          // 打开倍速选择菜单
          showMenu(
            context: context,
            color: const Color.fromARGB(125, 0, 0, 0),
            shape: RoundedRectangleBorder(
              borderRadius: BorderRadius.circular(10),
            ),
            position: RelativeRect.fromLTRB(50, 50, 0, 0),
            items: [
              PopupMenuItem(
                child: Center(
                  child: Text(
                    '0.5倍速',
                    style: TextStyle(color: Colors.white),
                  ),
                ),
                onTap: () {
                  videoController.setPlaybackSpeed(0.5);
                },
              ),
              PopupMenuItem(
                child: Center(
                  child: Text(
                    '1.0倍速',
                    style: TextStyle(color: Colors.white),
                  ),
                ),
                onTap: () {
                  videoController.setPlaybackSpeed(1.0);
                },
              ),
              PopupMenuItem(
                child: Center(
                  child: Text(
                    '1.5倍速',
                    style: TextStyle(color: Colors.white),
                  ),
                ),
                onTap: () {
                  videoController.setPlaybackSpeed(1.5);
                },
              ),
              PopupMenuItem(
                child: Center(
                  child: Text(
                    '2.0倍速',
                    style: TextStyle(color: Colors.white),
                  ),
                ),
                onTap: () {
                  videoController.setPlaybackSpeed(2.0);
                },
              ),
              PopupMenuItem(
                child: Center(
                  child: Text(
                    '3.0倍速',
                    style: TextStyle(color: Colors.white),
                  ),
                ),
                onTap: () {
                  videoController.setPlaybackSpeed(3.0);
                },
              ),
            ],
          );
        },
        child: Text(
          '倍速',
          style: TextStyle(color: Colors.white),
        ));
  }
}
